package com.ywl.study.sharding.study03.algorithm;



import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

@Slf4j
public class ModuloShardingTableAlgorithm implements PreciseShardingAlgorithm<Integer> {
    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {

        String tables=JSONObject.toJSONString(collection);
        log.info("可以选择范围:"+tables,preciseShardingValue.getValue());
        int value=preciseShardingValue.getValue();

        return "t_order"+(value%2);
    }
}
